package com.wormhole.wormholemanagement.controller;

import com.wormhole.wormholemanagement.entity.OperationLog;
import com.wormhole.wormholemanagement.service.OperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/operation-logs")
@Tag(name = "操作日志管理")
public class OperationLogController {

    private final OperationLogService logService;

    @Autowired
    public OperationLogController(OperationLogService logService) {
        this.logService = logService;
    }

    @GetMapping
    @Operation(summary = "获取操作日志列表")
    public ResponseEntity<Page<OperationLog>> getAllLogs(
            @PageableDefault(size = 10) Pageable pageable) {
        Page<OperationLog> logs = logService.getAllLogs(pageable);
        return ResponseEntity.ok(logs);
    }

    @GetMapping("/search")
    @Operation(summary = "搜索操作日志")
    public ResponseEntity<Page<OperationLog>> searchLogs(
            Specification<OperationLog> spec,
            @PageableDefault(size = 10) Pageable pageable) {
        Page<OperationLog> logs = logService.searchLogs(spec, pageable);
        return ResponseEntity.ok(logs);
    }
}
